<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Update User</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/updateUser.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/js/updateUser.js"></script>
</head>
<body onload="showErrorMessage()">
    <div class="content-container">
        <h2 class="page-title">更新用户信息</h2>
        <form action="${pageContext.request.contextPath}/updateUser" method="post" class="space-y-4">
            <input type="hidden" name="id" value="${user.id}">
            <div class="form-group">
                <label for="username">用户名:</label>
                <input type="text" id="username" name="username" value="${user.username}">
            </div>
            <div class="form-group">
                <label for="password">密码:</label>
                <input type="text" id="password" name="password" value="${user.password}">
            </div>
            <div class="form-group">
                <label for="balance">余额:</label>
                <input type="text" id="balance" name="balance" value="${user.balance}">
            </div>
            <div class="form-group">
                <label for="userpackage">用户套餐:</label>
                <select id="userpackage" name="userpackage">
                    <option value="1" <c:if test="${user.userpackage == 1}">selected</c:if>>套餐1: 20条短信, 1GB流量, 200分钟话费, 花费50元</option>
                    <option value="2" <c:if test="${user.userpackage == 2}">selected</c:if>>套餐2: 0条短信, 10GB流量, 0分钟话费, 花费60元</option>
                    <option value="3" <c:if test="${user.userpackage == 3}">selected</c:if>>套餐3: 50条短信, 5GB流量, 500分钟话费, 花费150元</option>
                </select>
            </div>
            <div class="flex justify-center">
                <input type="submit" value="保存修改" class="submit-btn">
            </div>
        </form>
        <!-- 添加返回按钮 -->
        <div class="flex justify-center mt-4">
            <button class="back-btn" onclick="window.location.href='${pageContext.request.contextPath}/getAllUsers'">返回管理员界面</button>
        </div>
        <!-- 添加一个隐藏的元素来存储 errorMessage，以便 JS 文件获取 -->
        <span id="errorMessage" style="display: none;">${errorMessage}</span>
    </div>
</body>
</html>